package com.orange.core.service.activityReview.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.orange.core.mapper.activityReview.ActivityReviewMapper;
import com.orange.core.pojo.PageReqDto;
import com.orange.core.pojo.entity.activityReview.ActivityReview;
import com.orange.core.pojo.entity.activityReview.dto.ActivityReviewDTO;
import com.orange.core.pojo.entity.activityReview.vo.ActivityReviewVO;
import com.orange.core.pojo.req.activityReview.ActivityReviewPageReq;
import com.orange.core.service.activityReview.ActivityReviewService;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
* @author lwm
* @description 针对表【activity_review(活动回顾)】的数据库操作Service实现
* @createDate 2025-07-11 16:34:15
*/
@Service
public class ActivityReviewServiceImpl extends ServiceImpl<ActivityReviewMapper, ActivityReview>
    implements ActivityReviewService {

    @Override
    public Page<ActivityReviewVO> page(PageReqDto<ActivityReviewPageReq> pageReqDto) {
        if(pageReqDto == null){
            pageReqDto = new PageReqDto<>();
            pageReqDto.setCondition(new ActivityReviewPageReq());
        }else if (pageReqDto.getCondition() == null){
            pageReqDto.setCondition(new ActivityReviewPageReq());
        }
        ActivityReviewPageReq condition = pageReqDto.getCondition();
        Page<ActivityReview> page = new Page<>(pageReqDto.getPage(),pageReqDto.getSize());
        LambdaQueryWrapper<ActivityReview> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(StrUtil.isNotBlank(condition.getTitle()),ActivityReview::getTitle,condition.getTitle())
               /* .between(condition.getStartTime() != null && condition.getEndTime() != null,
                        ActivityReview::getActivityTime,condition.getStartTime(),condition.getEndTime())*/
                .orderByDesc(ActivityReview::getId);
        page = this.page(page,queryWrapper);
        List<ActivityReviewVO> activityReviewVOList = page.getRecords().stream().map(activityReview -> {
            ActivityReviewVO activityReviewVO = new ActivityReviewVO();
            BeanUtil.copyProperties(activityReview, activityReviewVO);
            return activityReviewVO;
        }).collect(Collectors.toList());
        Page<ActivityReviewVO> activityReviewVOPage = new Page<>(pageReqDto.getPage(),pageReqDto.getSize(),page.getTotal());
        activityReviewVOPage.setRecords(activityReviewVOList);
        return activityReviewVOPage;
    }

    @Override
    public List<ActivityReviewVO> activityReviewList() {
        List<ActivityReview> list = this.list();
        List<ActivityReviewVO> activityReviewVOList = list.stream().map(activityReview -> {
            ActivityReviewVO activityReviewVO = new ActivityReviewVO();
            BeanUtil.copyProperties(activityReview, activityReviewVO);
            return activityReviewVO;
        }).collect(Collectors.toList());
        return activityReviewVOList;
    }

    @Override
    public boolean save(ActivityReviewDTO activityReviewDTO) {
        ActivityReview activityReview = new ActivityReview();
        BeanUtil.copyProperties(activityReviewDTO, activityReview);
        boolean result = this.save(activityReview);
        return result;
    }

    @Override
    public boolean update(ActivityReviewDTO activityReviewDTO) {
        ActivityReview activityReview = new ActivityReview();
        BeanUtil.copyProperties(activityReviewDTO, activityReview);
        boolean result = this.updateById(activityReview);
        return result;

    }

    @Override
    public boolean deleteActivityReviewByIds(Integer[] ids) {
        boolean result = this.removeBatchByIds(Arrays.asList(ids));
        return result;
    }
}




